#include <myheader_c_plus.h>
#include <memory>
using std::endl;
using std::cout;
using std::vector;
using std::unique_ptr;
using std::shared_ptr;
template<class T>
class RAII{
public:
    //构造函数
    RAII(T *data)
        :_data(data)
    {

    }


    //析构函数
    ~RAII(){
        if(_data){
            delete _data;
            _data = nullptr;
        }
    }

    //运算符重载
    T * operator->(){
        return *_data; 
    }


    T & operator*(){
        return _data;
    }

    void set(T * data){
        if(_data){
            delete _data;
        }
        _data = data;
    }

    void print(){
        cout << *_data << endl;
    }

    //不允许赋值或复制
    RAII & operator=(const RAII & rhs) = delete;
    RAII(const RAII & rhs) = delete;


private:
    T * _data;
};

class Point{
public:


private:
    int _x;
    int _y;
};
int main(int argc, char *argv[])
{
    int * data = new int(10);
    unique_ptr<int> up(data);
    unique_ptr<int> up2(new int(10));
    vector<unique_ptr<int>> vec;
    vec.push_back(std::move(up2));
    cout << *vec[0].get() << endl;

    cout << "=================" << endl;
    shared_ptr<int> sp(new int(100));
    cout << sp.use_count() << endl;
    shared_ptr<int> sp2 = sp;
    cout << sp.use_count() << endl;
    cout << sp2.use_count() << endl;
    vector<shared_ptr<int>> vec2;
    vec2.push_back(std::move(sp));
    vec2.push_back(sp2);
    cout << *vec2[0].get() << endl;
    cout << *vec2[1].get() << endl;
    cout << "====================" << endl;
    shared_ptr<int> sp3;
    int * data1 = new int(10);



    return 0;
}

